package com.theme.passport.controller.sys;

import com.theme.common.mvc.utils.PageUtils;
import com.theme.common.mvc.view.R;
import com.theme.passport.entity.theme.RecommendEntity;
import com.theme.passport.service.theme.RecommendService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;


/**
 * 推荐轮播图
 *
 * @author live
 * @email 870459550@qq.com
 * @date 2023-02-28 10:01:58
 */
@RestController
@RequestMapping("sys/recommend")
public class SysRecommendController {

    @Autowired
    private RecommendService recommendBannerService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:recommend:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = recommendBannerService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("sys:recommend:info")
    public R info(@PathVariable("id") Long id){
        RecommendEntity album = recommendBannerService.getById(id);

        return R.ok().put("recommend", album);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:recommend:save")
    public R save(@RequestBody RecommendEntity album){
        album.setCreated(new Date());
        recommendBannerService.save(album);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:recommend:update")
    public R update(@RequestBody RecommendEntity album){
        album.setUpdated(new Date());
        recommendBannerService.updateById(album);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:recommend:delete")
    public R delete(@RequestBody Long[] ids){
        recommendBannerService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
